// SystemPage.h
 
#ifndef __SYSTEM_PAGE_H
#define __SYSTEM_PAGE_H

#include "Common/Plugin/FilePlugins.h"

#include "resource.h"

const static int kRefreshpluginsListMessage  = WM_USER + 1;
const static int kUpdateDatabase = kRefreshpluginsListMessage  + 1;


class CSystemPage: public CPropertyPageImpl<CSystemPage>
{
	typedef CPropertyPageImpl<CSystemPage> baseClass;
public:
	enum { IDD = IDD_SYSTEM};

	BEGIN_MSG_MAP(CEditPage)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		MESSAGE_HANDLER(kRefreshpluginsListMessage, OnRefreshPluginList)
		MESSAGE_HANDLER(kUpdateDatabase, OnUpdateDatabase)
		COMMAND_ID_HANDLER(IDC_SYSTEM_SELECT_ALL, OnSelectAll)
		CHAIN_MSG_MAP(CPropertyPageImpl<CSystemPage>)
	END_MSG_MAP()

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnRefreshPluginList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		 RefreshPluginsList(-1);
		 return TRUE;
	};
	LRESULT OnUpdateDatabase(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		UpdateDatabase();
		return TRUE;
	};
	LRESULT OnSelectAll(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	
private:
  bool _initMode;
  Common::Plugin::CExtDatabase _extDatabase;

  CListViewCtrl _listViewExt;
  CListViewCtrl _listViewPlugins;

  void SetMainPluginText(int itemIndex, int indexInDatabase);

  int GetSelectedExtIndex();
  void RefreshPluginsList(int selectIndex);
  void MovePlugin(bool upDirection);
  void UpdateDatabase();
  void SelectAll();

public:
  bool WasChanged;
  CSystemPage(): WasChanged(false) {}
  void OnHelp();
  LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  bool OnItemChanged(const NMLISTVIEW *info);

  int OnApply();
  bool OnPluginsKeyDown(LPNMLVKEYDOWN keyDownInfo);
};

#endif
